{% extends 'layout/manage.html' %}

{% block content %}
    <div class="container-fluid project">
        <div style="margin: 10px 0;">
            <a class="btn btn-primary" data-toggle="modal" data-target="#addModal">
                <i class="fa fa-plus-circle" aria-hidden="true"></i> 添加新用户
            </a>
        </div>
    </div>
<!-- Modal -->
    <div class="panel panel-default">
        <div class="panel-heading">所有用户信息列表</div>
        <div class="panel-body">
           {% for new in data %}
               <p>&emsp;用户名：{{new.username}}&emsp;
                   用户密码：{{ new.password }}&emsp;
                   用户手机号：{{new.mobile_phone}}&emsp;
                   用户电子邮箱：{{new.email}}&emsp;
               </p>

            {% endfor %}

        </div>
    </div>








    <div class="modal fade" id="addModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span
                            aria-hidden="true">&times;</span></button>
                    <h4 class="modal-title" id="myModalLabel">添加新用户</h4>
                </div>
                <div class="modal-body">
                    <form id="addForm">
                        {% csrf_token %}
                        {% for field in form %}
                            <div class="form-group">
                                <label for="{{ field.id_for_label }}">{{ field.label }}</label>
                                {{ field }}
                                <span class="error-msg"></span>
                            </div>
                        {% endfor %}
                    </form>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-default" data-dismiss="modal">取 消</button>
                    <button id="btnSubmit" type="button" class="btn btn-primary">确 定</button>
                </div>
            </div>
        </div>
    </div>

{% endblock %}

{% block js %}
    <script>
        $(function () {
            bindSubmit();
        });

        /*
            新建项目提交
         */
        function bindSubmit() {
            $('#btnSubmit').click(function () {
                $.ajax({
                    url: '{% url 'project_list2' %}',
                    type: 'POST',
                    data: $('#addForm').serialize(),
                    dataType: 'JSON',
                    success: function (res) {
                        if (res.status) {
                            //location.href = location.href
                            location.reload();
                        } else {
                            $.each(res.error, function (key, value) {
                                $("#id_" + key).next().text(value[0]);
                            });
                        }
                    }
                });
            });
        }


    </script>
{% endblock %}
